const { ADD_NUMBER, CHANGE_NAME } = require("./constants")

// 初始化数据
const initialState = {
    name: "baki",
    counter: 100,
}

function reducer(state = initialState, action) {
    // 有新数据进行更新的时候，那么返回一个新的state
    switch (action.type) {
        case CHANGE_NAME:
            return { ...state, name: action.name }
        case ADD_NUMBER:
            return { ...state, counter: state.counter + action.counter }
        default:
            return state
    }
}

model.exports = reducer